package com.ljx.itbbs.server.mall.service.strategy;

import com.ljx.itbbs.common.domain.enums.CommonErrorEnum;
import com.ljx.itbbs.common.utils.AssertUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: LiJunXi
 * @Description: 订单处理工厂
 * @Date: 2024-03-29  17:18
 */
public class OrderHandlerFactory {

    private static final Map<Integer, AbstractOrderHandler> STRATEGY_MAP = new HashMap<>();

    public static void register(Integer code, AbstractOrderHandler strategy) {
        STRATEGY_MAP.put(code, strategy);
    }

    public static AbstractOrderHandler getStrategyNoNull(Integer type) {
        AbstractOrderHandler strategy = STRATEGY_MAP.get(type);
        AssertUtil.isNotEmpty(strategy, CommonErrorEnum.PARAM_INVALID.getDesc());
        return strategy;
    }

}
